package springdidemo.config;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.beans.ConstructorProperties;
import java.util.List;
import java.util.Map;

@RestController
public class PropertiesController {
    @Autowired
    public Student stu;
@RequestMapping("/m2")
    public String student(){
        return stu.toString();
    }

    @Value("${my.value}")
    public  String key1;
    @RequestMapping("/m1")
    public String key(){
        return "读取到"+key1;
    }

    @Autowired
    public Dbtypes dbtypes;
    @RequestMapping("/m3")
    public String getlist(){
        return "读取到"+dbtypes.toString();
    }

    //集合，非基本类型要封装到对象里才可以
//    @Value("${dbtypes.ball}")
//    public Map<String,String> ball;


    @Value("${string.str1}")
    public String str1;
    @Value("${string.str2}")
    public String str2;
    @Value("${string.str3}")
    public String str3;

    @RequestMapping("/m5")
    public String getstr(){
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);//双引号不会转意
        return "yml";
    }

    @PostConstruct
    public void init(){
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        System.out.println(dbtypes);
//        System.out.println(ball);
    }

}
